import React from 'react';
function hoc(WithComponent) {
    return class hocComponent extends React.Component{
        constructor(){
            super();
            this.state={
                bShow:false,
                aPosList:[]
            }
        }
        //点击展开隐藏详细描述
        onClickPost(index){
            let temAPosList=this.props.aPosList;
                if (temAPosList[index].bChecked) {
                    temAPosList[index].bChecked=false
                }else {
                    for (let i in temAPosList){
                        temAPosList[i].bChecked=false;
                        temAPosList[index].bChecked=true
                    }

                }

            this.setState({aPosList:temAPosList});
        }
        //点击跳转页面
        goPages(url){
            let strUrl = "^(://)" +
                "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" +//ftp的user@+
                "(([0-9]{1,3}.){3}[0-9]{1,3}" +// IP形式的URL- 199.194.52.184 +
                "|" +// 允许IP和DOMAIN（域名） +
                "([0-9a-z_!~*'()-]+.)*" +// 域名- www. +
                "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]." +// 二级域名 +
                "[a-z]{0,6})" +// first level domain- .com or .museum +
                "(:[0-9]{1,4})?" +// 端口- :80 +
                "((/?)|"  +// a slash isn't required if there is no file name +
                "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";

            let reg = new RegExp(strUrl);
            if (!reg.test(url)){
                window.open(url)
            }else {
                this.props.history.push(window.base.config.path+url)
            }
        }
        render(){
            let newsProps={
                goPages:this.goPages.bind(this),
                onClickPost:this.onClickPost.bind(this),
                bShow:this.state.bShow,
            }
            return(
                <WithComponent {...this.props} {...newsProps}></WithComponent>
            )
        }
    }
}
export default hoc